<template>
  <div>
    <h1>CountSUm:{{ sum }}</h1>
    <h1>人员列表</h1>
    <input type="text" placeholder="请输入姓名" v-model="name">
    <button @click="add()">添加</button>
    <ul>
        <li v-for="person in persons" :key="person.id">
            {{ person.id }} : {{ person.name }}
        </li>
    </ul>
  </div>
</template>

<script>
    import {nanoid} from 'nanoid'
    import { mapState } from 'vuex';
    export default {
        name:'Person',
        data(){
            return {
                name:'',
            }
        },
        computed:{
            ...mapState('countAbout',['sum']),
            ...mapState('personAbout',['persons']),
            
        },
        methods:{
            add(){
                let personObj = {id:nanoid(),name:this.name}
                this.$store.commit('personAbout/ADD',personObj)
                this.name = ''
            }
        }
    }
</script>

<style>

</style>